package tests;

import static org.junit.Assert.assertTrue;
import gestioneDatabase.User.AllUsersRetriever;
import gestioneDatabase.User.UserInserter;
import gestioneDatabase.User.UserManager;

import java.util.HashMap;

import models.User;

import org.junit.Before;
import org.junit.Test;

public class TestUserManager {
	
	UserManager userManager = UserManager.getUserManager();
	AllUsersRetriever allUsersRetriever = null;
	HashMap<String, User> users = null;
	UserInserter userInserter = null;
	User userToInsert = null;
	
	@Before
	public void createTestHashMap(){
		allUsersRetriever = new AllUsersRetriever();
		users = allUsersRetriever.getUsers();
	}
	
	@Test
	public void testGetUsers() {
		HashMap<String, User> testUsers = userManager.getUsers();
		System.out.println(testUsers.size());
	}

	@Test
	public void testInsertUsers(){
		userToInsert = new User("User1");
		userToInsert.setEmailAddress("user1@gmail.com");
		userToInsert.setOpenId("user1");
		userToInsert.setStylesheet("capuccino");
		userManager.InsertUser(userToInsert);
		try {
			wait();
		} catch (Exception e) {
		}
		assertTrue(userManager.getUsers().size() == users.size());
	}
	
	@Test
	public void testFillSingleUser() {
		User fillUser = userManager.fillSingleUser("UsEr2", "user2", "user2.gmail.com", "Mint");
		assertTrue((fillUser.getFullName().equals("user2") && fillUser.getOpenId().equals("UsEr2") 
					&& fillUser.getEmailAddress().equals("user2.gmail.com"))	&& (fillUser.getStylesheet().equals("Mint")));
	}
	
}
